<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态组件和状态保存</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.0.2/vue.global.js"></script>
    
    

</head>

<body>
    <div id="app"></div>
</body>
<script>
    const app = Vue.createApp({
        data() {
            return {
                isShowFlag:'course01'
            }
        },
        methods: {
            handleClick() {
                this.isShowFlag = this.isShowFlag==='course01' ?  "course02" : "course01"
            }
        },
        template: ` 
            <h2>唯爱薇o朝圣之路</h2>

            <!-- 静态组件 -->
            <!-- <hr\> 
            <course01 v-show="isShowFlag==='course01'" />
            <course02 v-show="isShowFlag==='course02'" /> -->
            <!-- 动态组件,且保持状态 -->
            <keep-alive>
                <component :is="isShowFlag" />
            </keep-alive>
            <hr\> 
            <button @click="handleClick">切换课程</button>
        `
    })
    app.component('course01',{
        //template:`<img src="http://edu.vlovev.cn/files/course/2019/10-20/203443345d3c906873.jpg" />`
        template:`<input type="search" placeholder="请输入课程内容">`
    })
    
    app.component('course02',{
        template:`<img src="http://edu.vlovev.cn/files/course/2019/08-11/12003425ebc8208544.png" />`
    })

    const vm = app.mount("#app")
</script>